package com.itzixi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itzixi.bean.ChatRecord;
import com.itzixi.mapper.ChatRecordMapper;
import com.itzixi.service.ChatRecordService;
import com.itzixi.utils.ChatTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName ChatRecordServiceImpl
 * @Author 风间影月
 * @Version 1.0
 * @Description ChatRecordServiceImpl
 **/
@Service
public class ChatRecordServiceImpl extends ServiceImpl<ChatRecordMapper,ChatRecord> implements ChatRecordService {

    @Resource
    private ChatRecordMapper chatRecordMapper;

    @Override
    /**
     * 保存聊天记录的方法
     * @param userName 用户名称
     * @param message 聊天内容
     * @param chatType 聊天类型枚举
     */
    public void saveChatRecord(String userName, String message, ChatTypeEnum chatType) {

        // 创建聊天记录对象
        ChatRecord chatRecord = new ChatRecord();
        // 设置聊天记录的时间为当前时间
        chatRecord.setChatTime(LocalDateTime.now());
        // 设置聊天记录的发送者用户名
        chatRecord.setFamilyMember(userName);
        // 设置聊天记录的具体内容
        chatRecord.setContent(message);
        // 设置聊天记录的类型
        chatRecord.setChatType(chatType.type);

        // 将聊天记录插入到数据库中
        chatRecordMapper.insert(chatRecord);
    }

    @Override
    public List<ChatRecord> getChatRecordList(String who) {

        QueryWrapper<ChatRecord> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("family_member", who);

        return  chatRecordMapper.selectList(queryWrapper);



    }
}
